home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / customs / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  4.0 KB  |  153 lines

  1. /*-
  2.  * log.c --
  3.  *    Functions to talk to a logging server via udp RPC.
  4.  *
  5.  * Copyright (c) 1988, 1989 by the Regents of the University of California
  6.  * Copyright (c) 1988, 1989 by Adam de Boor
  7.  * Copyright (c) 1989 by Berkeley Softworks
  8.  *
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any non-commercial purpose
  11.  * and without fee is hereby granted, provided that the above copyright
  12.  * notice appears in all copies.  The University of California,
  13.  * Berkeley Softworks and Adam de Boor make no representations about
  14.  * the suitability of this software for any purpose.  It is provided
  15.  * "as is" without express or implied warranty.
  16.  */
  17. #ifndef lint
  18. static char *rcsid =
  19. "$Id: log.c,v 1.6 89/11/14 13:46:09 adam Exp $ SPRITE (Berkeley)";
  20. #endif lint
  21.  
  22. #include    "customsInt.h"
  23. #include    "log.h"
  24. #include    <varargs.h>
  25.  
  26. static Boolean                logServer;
  27. static struct sockaddr_in   logServerAddr;
  28. static int                numFails;
  29.  
  30. #define NUM_FAILS_ALLOWED   3    /* Number of failures allowed before log
  31.                  * server is evicted */
  32. /*-
  33.  *-----------------------------------------------------------------------
  34.  * Log_Send --
  35.  *    Send a message to the log server. Encodes the arguments using
  36.  *    XDR functions and sends an RPC call on the log socket.
  37.  *
  38.  * Results:
  39.  *    None.
  40.  *
  41.  * Side Effects:
  42.  *    logServer will be set FALSE if an error occurs.
  43.  *
  44.  *-----------------------------------------------------------------------
  45.  */
  46. /*VARARGS2*/
  47. void
  48. Log_Send (procNum, pieces, va_alist)
  49.     Rpc_Proc                 procNum;      /* Procedure to call for log server */
  50.     int                      pieces;     /* Number of pieces of data to
  51.                      * encode */
  52.     va_dcl
  53. {
  54.     XDR                      stream;       /* Memory stream for encoding */
  55.     va_list               args;        /* Var for accessing arguments */
  56.     xdrproc_t              encode;       /* Function to encode data */
  57.     caddr_t               data;        /* Data to encode */
  58.     char                  logBuf[MAX_DATA_SIZE];
  59.     int                    len;    /* Length of encoded data */
  60.  
  61.     if (logServer) {
  62.     xdrmem_create (&stream, logBuf, sizeof(logBuf), XDR_ENCODE);
  63.  
  64.     /*
  65.      * Encode each piece of data using the xdr function given for it.
  66.      */
  67.     va_start(args);
  68.     while (pieces--) {
  69.         encode = va_arg(args, xdrproc_t);
  70.         data = va_arg(args, caddr_t);
  71.         if (!(*encode) (&stream, data)) {
  72.         logServer = FALSE;
  73.         return;
  74.         }
  75.     }
  76.     va_end (args);
  77.  
  78.     /*
  79.      * All pieces now encoded, send the buffer off to the server using
  80.      * the standard, short, internal timeout and resend values.
  81.      */
  82.     len = XDR_GETPOS(&stream);
  83.     if (Rpc_Call(udpSocket, &logServerAddr, procNum,
  84.              len, (Rpc_Opaque)logBuf,
  85.              0, (Rpc_Opaque)0,
  86.              CUSTOMSINT_NRETRY, &retryTimeOut) != RPC_SUCCESS)
  87.     {
  88.         if (--numFails == 0) {
  89.         logServer = FALSE;
  90.         }
  91.     } else {
  92.         numFails = NUM_FAILS_ALLOWED;
  93.     }
  94.     }
  95. }
  96.  
  97. /*-
  98.  *-----------------------------------------------------------------------
  99.  * LogStart --
  100.  *    Start up a log connection with another process.
  101.  *
  102.  * Results:
  103.  *    None.
  104.  *
  105.  * Side Effects:
  106.  *    Of course.
  107.  *
  108.  *-----------------------------------------------------------------------
  109.  */
  110. /*ARGSUSED*/
  111. static void
  112. LogStart(from, msg, len, data)
  113.     struct sockaddr_in    *from;
  114.     Rpc_Message          msg;
  115.     int                  len;
  116.     Boolean           *data;        /* TRUE if should evict previous server */
  117. {
  118.     if (logServer) {
  119.     if (len != sizeof(Boolean)) {
  120.         Rpc_Error(msg, RPC_BADARGS);
  121.     } else if (! *data) {
  122.         Rpc_Error(msg, RPC_ACCESS);
  123.         return;
  124.     } else {
  125.         Rpc_Return(msg, 0, (Rpc_Opaque)0);
  126.         Log_Send(LOG_EVICT, 1, xdr_sockaddr_in, from);
  127.     }
  128.     } else {
  129.     Rpc_Return(msg, 0, (Rpc_Opaque)0);
  130.     }
  131.     logServer = TRUE;
  132.     logServerAddr = *from;
  133.     numFails = NUM_FAILS_ALLOWED;
  134. }
  135.  
  136. /*-
  137.  *-----------------------------------------------------------------------
  138.  * Log_Init --
  139.  *
  140.  * Results:
  141.  *
  142.  * Side Effects:
  143.  *
  144.  *-----------------------------------------------------------------------
  145.  */
  146. void
  147. Log_Init()
  148. {
  149.     logServer = FALSE;
  150.     Rpc_ServerCreate(udpSocket, (Rpc_Proc)CUSTOMS_LOG, LogStart,
  151.              Rpc_SwapLong, Rpc_SwapNull, (Rpc_Opaque)0);
  152. }
  153.